//
//  RejectOperationView.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/7/7.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "RejectOperationView.h"

@interface RejectOperationView ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *timeLab;
@property (nonatomic, strong) UILabel *descLab;
@property (nonatomic, strong) UIButton *modifyBtn;
@property (nonatomic, strong) UIButton *deleteBtn;

@end

@implementation RejectOperationView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = HexColor(0xffffff);
        
        self.bgView = [UIView new];
        self.bgView.backgroundColor = HexColor(0xF35959);
        self.bgView.layer.cornerRadius = 6;
        //设置阴影颜色
        self.bgView.layer.shadowColor = HexColorA(0xF35959, 0.5).CGColor;
        //设置阴影的透明度
        self.bgView.layer.shadowOpacity = 1.f;
        //设置阴影的偏移
        self.bgView.layer.shadowOffset = CGSizeMake(0.0f, 4.0f);
        //设置阴影半径
        self.bgView.layer.shadowRadius = 10.0f;
        [self addSubview:self.bgView];
        
        self.titleLab = [UILabel new];
        self.titleLab.textColor = HexColor(0xffffff);
        self.titleLab.font = BoldFontOfSize(18);
        [self.bgView addSubview:self.titleLab];
        
        self.timeLab = [UILabel new];
        self.timeLab.textColor = HexColor(0xffffff);
        self.timeLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.timeLab];
        
        self.descLab = [UILabel new];
        self.descLab.textColor = HexColor(0xffffff);
        self.descLab.font = [UIFont systemFontOfSize:12];
        self.descLab.numberOfLines = 3;
        [self.bgView addSubview:self.descLab];
        
        self.modifyBtn = [UIButton new];
        [self.modifyBtn setTitle:@"修改提货单" forState:0];
        [self.modifyBtn setTitleColor:HexColor(0xffffff) forState:0];
        self.modifyBtn.titleLabel.font = BoldFontOfSize(16);
        self.modifyBtn.backgroundColor = HexColor(0xFBA962);
        self.modifyBtn.layer.masksToBounds = YES;
        self.modifyBtn.layer.cornerRadius = 6;
        [self.modifyBtn addTarget:self action:@selector(modifyClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.modifyBtn];
        
        self.deleteBtn = [UIButton new];
        [self.deleteBtn setTitle:@"作废" forState:0];
        [self.deleteBtn setTitleColor:HexColor(0xffffff) forState:0];
        self.deleteBtn.titleLabel.font = BoldFontOfSize(16);
        self.deleteBtn.backgroundColor = [UIColor clearColor];
        self.deleteBtn.layer.masksToBounds = YES;
        self.deleteBtn.layer.cornerRadius = 6;
        self.deleteBtn.layer.borderWidth = 2;
        self.deleteBtn.layer.borderColor = HexColorA(0xffffff, 0.4).CGColor;
        [self.deleteBtn addTarget:self action:@selector(deleteClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.deleteBtn];
    }
    return self;
}

- (void)modifyClick {
    if (self.modifyBlock) {
        self.modifyBlock();
    }
}

- (void)deleteClick {
    if (self.deleteBlock) {
        self.deleteBlock();
    }
}

-(void)setCanOperation:(BOOL)canOperation {
    _canOperation = canOperation;
    self.height = canOperation ? 221 : 168;
    self.bgView.nim_left = 15;
    self.bgView.nim_top = 10;
    self.bgView.nim_width = ScreenW - 2 * self.bgView.nim_left;
    self.bgView.nim_height = canOperation ? 196 : 143;
    
    self.titleLab.nim_left = 20;
    self.titleLab.nim_top = 20;
    self.titleLab.nim_width = self.bgView.nim_width - 40;
    self.titleLab.nim_height = 20;
    
    self.timeLab.nim_left = self.titleLab.nim_left;
    self.timeLab.nim_top = self.titleLab.nim_bottom + 5;
    self.timeLab.nim_width = self.titleLab.nim_width;
    self.timeLab.nim_height = 13;
    
    self.descLab.nim_left = self.titleLab.nim_left;
    self.descLab.nim_top = self.timeLab.nim_bottom + 10;
    self.descLab.nim_width = self.titleLab.nim_width;
    
    if (canOperation) {
        self.descLab.nim_height = self.bgView.nim_height - 15 - 38 - 20 - self.descLab.nim_top;
        
        self.modifyBtn.frame = CGRectMake(self.titleLab.nim_left, self.descLab.nim_bottom + 20, 120, 38);
        self.deleteBtn.frame = CGRectMake(self.modifyBtn.nim_right + 10, self.modifyBtn.nim_top, 120, 38);
    }else {
        self.modifyBtn.frame = CGRectZero;
        self.deleteBtn.frame = CGRectZero;
        self.descLab.nim_height = self.bgView.nim_height - 20 - self.descLab.nim_top;
    }
}

-(void)setTitleStr:(NSString *)titleStr {
    _titleStr = titleStr;
    self.titleLab.text = titleStr;
}

-(void)setTimeStr:(NSString *)timeStr {
    _timeStr = timeStr;
    self.timeLab.text = timeStr;
}

-(void)setDescStr:(NSString *)descStr {
    _descStr = descStr;
    self.descLab.text = descStr;
}

@end
